package com.zelin.dao.impl;

import com.zelin.dao.StudentDao;
import com.zelin.pojo.Student;
import com.zelin.util.Application;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @Auther zxh
 * @Date 2020/9/28下午 4:38
 */
public class StudentDaoImpl implements StudentDao {

    private QueryRunner queryRunner = new QueryRunner(Application.getDataSource()) ;
   /* public StudentDaoImpl(){
        runner = new QueryRunner(Application.getDataSource());
    }*/

    @Override
    public List<Student> query() throws SQLException {
        return queryRunner.query("select * from student",new BeanListHandler<>(Student.class));
    }

    @Override
    public void insert(Student student) throws SQLException {
        queryRunner.update("insert into student values(null,?,?,?,?,?)",
                student.getStuno(),student.getStuname(),student.getClassno(),
                student.getSex(),student.getAge(),student.getClassname());
    }
}
